#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sina_sso import sina_sso
from weibo import APIClient
from config import USERNAME, APP_KEY, APP_SECRET, PASSWD, REDIRECT_URL
import requests

api_client = APIClient(APP_KEY, APP_SECRET, REDIRECT_URL)    
authorize_url = api_client.get_authorize_url()

try:
    auth_code = sina_sso(authorize_url)
except requests.exceptions.ConnectionError:
    auth_code = sina_sso(authorize_url)
    
token = api_client.request_access_token(auth_code)

api_client.set_access_token(token.access_token, token.expires_in)

while (True):
    status = raw_input('发个新浪微波吧: ')
    api_client.post.statuses__update(status=status)
    print "OK\n"
